package com.chzu.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chzu.mapper.ScoreInfoMapper;
import com.chzu.pojo.ScoreInfo;
import com.chzu.pojo.vo.ScoreInfoVo;
import com.chzu.pojo.vo.StudentExamInfo;
import com.chzu.result.JsonResult;
import com.chzu.result.PageResult;
import com.chzu.result.QueryInfo;
import com.chzu.service.ScoreInfoService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lz
 * @Version 1.0
 * @Company 滁州大健康与养老产业研究院
 * @ClassName ScoreInfoServiceImpl
 * @Description TODO
 * @Date 2022/02/22 21:41
 */
@Service
public class ScoreInfoServiceImpl extends ServiceImpl<ScoreInfoMapper, ScoreInfo> implements ScoreInfoService {

    @Resource
    private ScoreInfoMapper scoreInfoMapper;

    /**
     * 分页查询学生的成绩信息
     * @param queryInfo 模糊查询
     * @return
     */
    @Override
    public JsonResult<Object> getScoreInfo(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(),queryInfo.getPageSize());
        Page<ScoreInfoVo> page = scoreInfoMapper.getScoreInfo(queryInfo.getQueryString());
        long total = page.getTotal();
        List<ScoreInfoVo> result = page.getResult();
        return PageResult.pageResult(result,total);
    }

    /**
     * 分页获得所有学生的所有次考试成绩信息
     * @param queryInfo 模糊查询
     * @return
     */
    @Override
    public JsonResult<Object> getAllStudentExamInfo(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(),queryInfo.getPageSize());
        Page<StudentExamInfo> page = scoreInfoMapper.getAllStudentExamInfo(queryInfo.getQueryString());
        long total = page.getTotal();
        List<StudentExamInfo> result = page.getResult();
        return PageResult.pageResult(result,total);
    }

    /**
     * 获得最新一次考试学生的成绩
     * @return
     */
    @Override
    public List<Integer> getLastExamScore() {
        return scoreInfoMapper.getLastExamScore();
    }

    /**
     * 判断当前用户是否已经进行了测试
     * @param userId 学生的学号
     * @param paperId 试卷Id
     * @return 查询的条数
     */
    @Override
    public int hasTesting(String userId, String paperId) {
        return scoreInfoMapper.hasTesting(userId, paperId);
    }
}
